package com.qijian.web.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qijian.common.annotation.Log;
import com.qijian.common.core.controller.BaseController;
import com.qijian.common.core.domain.AjaxResult;
import com.qijian.common.core.domain.entity.SysMenuLike;
import com.qijian.common.core.page.TableDataInfo;
import com.qijian.common.enums.BusinessType;
import com.qijian.common.utils.SecurityUtils;
import com.qijian.common.utils.mybatis.WhereEntityTool;
import com.qijian.system.service.ISysMenuLikeService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户常用菜单Controller
 *
 * @author qijian
 * @date 2022-01-17
 */
@Api(tags = "用户常用菜单")
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/menu/like")
public class SysMenuLikeController extends BaseController {

    private final ISysMenuLikeService menuLikeService;

    /**
     * 新增用户常用菜单
     */
//    @PreAuthorize("@ss.hasPermi('business:like:add')")
    @Log(title = "用户常用菜单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMenuLike menuLike) {
        menuLike.setUserId(SecurityUtils.getUserId());
        return toAjax(menuLikeService.save(menuLike));
    }

    /**
     * 删除用户常用菜单
     */
//    @PreAuthorize("@ss.hasPermi('business:like:remove')")
    @Log(title = "用户常用菜单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(menuLikeService.removeByIds(ids));
    }

//    @PreAuthorize("@ss.hasPermi('business:like:remove')")
    @Log(title = "用户常用菜单", businessType = BusinessType.DELETE)
    @DeleteMapping
    public AjaxResult removeOne(@RequestParam Long menuId) {
        SysMenuLike menuLike = new SysMenuLike();
        menuLike.setUserId(SecurityUtils.getUserId());
        menuLike.setMenuId(menuId);
        return toAjax(menuLikeService.remove(WhereEntityTool.invoke(menuLike)));
    }
}
